package cn.edu.jlu.community.app.start;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import com.avos.avoscloud.AVUser;

import cn.edu.jlu.community.R;
import cn.edu.jlu.community.app.MainActivity;
import cn.edu.jlu.community.app.base.AbstractActivity;
import cn.edu.jlu.community.app.sign.SignActivity;
import cn.edu.jlu.community.util.Log;

/**
 * Startup activity
 *
 * @author kode
 */
public class StartupActivity extends AbstractActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.splash_layout);

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                startProperActivity();
                finish();
            }
        }, 1000);
    }

    /**
     * Collect app startup info then jump to a proper activity.
     */
    private void startProperActivity() {

        AVUser currentUser = AVUser.getCurrentUser();
        if (currentUser != null) {
            startActivity(MainActivity.class);
        } else {
            startActivity(SignActivity.class);
        }
    }

    private void startActivity(Class<?> cls) {
        Log.v("start activity " + cls.getSimpleName());
        this.startActivity(new Intent(this, cls));
    }
}
